<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 首页
     *
     */
    public function index()
    {
        $this->success('请求成功');
    }

    //验证订单
    public function verifyorder(){

        $ordersn=$this->request->param('ordersn');


        if(!$ordersn){
            $this->success('无订单号');
        }

        $order= Db::name('order')
            ->where(['ordersn'=>$ordersn])
            ->find();


        if  (!$order){

            $ordersn1['name']='测试信息';
            $ordersn1['number']=3;
            $ordersn1['user']='用户';
            $ordersn1['ordersn']=$ordersn;

            Db::name('order')
                ->data($ordersn1)
                ->insert();
//            $this->success('未找到订单');
        }



        if  ($order&&$order['status']!=0){
            $this->error('订单已经完成');
        }

        $order= Db::name('order')
            ->where(['ordersn'=>$ordersn])
            ->find();

        $this->success('验证通过',$order);

    }


}
